﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WallpaperDemo.Models;

namespace WallpaperDemo.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SearchController : ControllerBase
    {
        private readonly WallpapersContext _context;
        private WallpaperService wallpaperService;

        public SearchController(WallpapersContext context)
        {
            _context = context;
            wallpaperService = new WallpaperService(context);
        }

        //GET: api/Search/glass
        [HttpGet("{keyword}")]
        public ActionResult<List<Wallpaper>> GetWallpaper_Search(string keyword, int seq)
        {
            if (_context.Wallpapers == null)
            {
                return NotFound();
            }
            var wallpaper = wallpaperService.QueryWallpaper_SingleKey(keyword, seq);

            if (wallpaper == null)
            {
                return NotFound();
            }

            return wallpaper;
        }
    }
}
